//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    changeClass: "none",
    changeButton: true,
    animationData: {}
  },
  onLoad: function(event) {
    var postUrl = 'https://api.topeffects.cn/i/activity/index';
    var activity_id = 190;
    var spm = '27.175.23.238';
    var latest_time = Date.parse(new Date());
    var put_system;
    wx.getSystemInfo({
      success: function(res) {
        var system = res.system.split(" ");
        if (system[0] == 'iOS') {
          put_system = 2;
        } else if (system[0] == 'Android') {
          put_system = 3;
        } else {
          put_system = 4;
        }
      }
    })
    // this.getAllMess(postUrl, activity_id, spm, latest_time, put_system);
  },
  onShow: function() {
    // 动画开始
    var animation = wx.createAnimation({
      timingFunction: 'ease',
      duration: 4000
    })
    this.animationIndex=1;
    this.animation = animation
  },
  // 跳转规则页面
  turnRule: function(event) {
    wx.navigateTo({
      url: '../rule/rule',
    })
  },
  // 跳转我的奖品页面
  turnPrize: function(event) {
    wx.navigateTo({
      url: '../prize/prize',
    })
  },
  // 关闭中奖弹出层
  closePage: function(event) {
    this.setData({
      changeClass: "none",
      changeButton: true
    })
  },
  // 抽奖按钮
  clickButton: function(event) {
    var that=this
    this.rotateImg();
    // setTimeout(function() {
        // this.setData({
          // changeButton: false,
          // changeClass: 'getPrzie'
          // animationData: {}
        // })
      // this.data.animationData = {}
    // }.bind(this), 4500)
  },
  // 请求数据
  getAllMess: function(postUrl, activity_id, spm, latest_time, put_system) {
    console.log(postUrl);
    wx.request({
      url: postUrl,
      method: "POST",
      data: {
        activity_id: activity_id,
        spm: spm,
        latest_time: latest_time,
        put_system: put_system
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function(res) {
        console.log(res.data)
      }
    })
  },
  // 动画
  rotateImg: function() {
    this.animationIndex++;
    this.animation.rotate(3660*this.animationIndex).step()
    // console.log(this.animation.export())
    this.setData({
      animationData: this.animation.export()
    })
    // setTimeout(function(){
    //   that.animation.rotate(0).step()
    //   that.setData({
    //     animationData: that.animation.export()
    //   })
    // },5000)
  },

})